package mn.slide.petrovis.home;
import java.util.ArrayList;
import mn.slide.petrovis.R;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

public class HomeTabGroupActivity extends ActivityGroup
{

	private ArrayList<View>				history;
	public static HomeTabGroupActivity	group;
	Animation							outToLeft;
	Animation							inFromRight;
	Animation							inFromLeft;
	Animation							outToRight;

	@Override
	protected void onCreate( Bundle savedInstanceState )
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		group = this;
		history = new ArrayList<View>();
		View view = getLocalActivityManager().startActivity("ListView", new Intent(this, HomeActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
		replaceView(view);

	}

	public void goTo( Intent intent )
	{
		View view;
		if (intent.getComponent().getShortClassName().equals(".StandardLaborActivity"))
		{
			view = getLocalActivityManager().startActivity("MapActivity", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
		}
		else
		{
			view = getLocalActivityManager().startActivity("ListView", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
		}
		replaceView(view);

	}

	public void replaceView( View v )
	{

		outToLeft = AnimationUtils.loadAnimation(this, R.anim.out_to_left);
		inFromRight = AnimationUtils.loadAnimation(this, R.anim.in_from_right);
		if (history.size() > 0)
		{
			View v1 = history.get(history.size() - 1);
			v1.setAnimation(outToLeft);
			v.setAnimation(inFromRight);
		}
		history.add(v);
		setContentView(v);

	}

	public void back()
	{
		if (history.size() > 0)
		{
			inFromLeft = AnimationUtils.loadAnimation(this, R.anim.in_from_left);
			outToRight = AnimationUtils.loadAnimation(this, R.anim.out_to_right);
			View v = history.get(history.size() - 1);
			v.setAnimation(outToRight);
			history.remove(history.size() - 1);
			v = history.get(history.size() - 1);
			v.setAnimation(inFromLeft);
			setContentView(v);
		}
		else
		{
			finish();
		}
	}

	@Override
	public void onBackPressed()
	{
		back();
	}

}
